﻿using System;
using System.Data;
using BEGDC.CC.BL.Common.Query;
using BEGDC.CC.Entity;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.CCFlow.EV;

namespace BEGDC.CC.Web.UserControls.EV
{
	/// <summary>
	/// Summary description for BaseEV.
	/// </summary>
	public class BaseEV : BaseCtrl
	{
		public BaseEV()
		{
		}

		protected override int AppID
		{
			
			get
			{ 
				if( this.ViewState["AppID"] == null )
				{
					if( Request["AppID"] == null ) return 0;
					else return Convert.ToInt32( Request["AppID"] );
				}
				else
				{
					if( Request["AppID"] != null && this.ViewState["AppID"] != Request["AppID"] )
						return Convert.ToInt32( Request["AppID"] );
				}
				return (int)this.ViewState["AppID"]; 
			}
			set
			{
				base.AppID = value;
			}
		}

		protected bool IsQuery
		{
			get
			{
				string state = this.Request.QueryString["State"];
				if(state == null) return false;
				return state == SysDicItem.ProjectStatusFlag.QUERY;
			}
		}

		protected virtual void ControlStatusSetting()
		{
		}

		/// <summary>
		/// Initialize common information
		/// </summary>
		protected void InitCommonData()
		{
			IQuery querySerive = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;
			base.Application = querySerive.GetAppById( AppID );
		}

		#region Accessibility status setting
		protected bool IsCurrentStep(string stepName)
		{
			try
			{
				IEV evService = BEGDC.Utility.Castle.AppContainer.Instance[ServiceConst.EVService] as IEV;
				return evService.IsCurrentStep( this.AppID, stepName );
			}
			catch(BEGDC.Utility.ExceptionManagement.GDCException gdcEx)
			{
				throw gdcEx;
			}
			

		}

		protected Accessibility CheckAccessibility(string roleName)
		{
			return base.CheckAccessibility (System.Web.HttpContext.Current.User.Identity.Name, roleName);
		}

		protected Accessibility CheckAccessibility(string stepName, string roleName)
		{
			return base.CheckAccessibility (stepName, roleName, System.Web.HttpContext.Current.User.Identity.Name, this.AppID);
		}

		#endregion

	}
}
